<template>
  <div class='box'>
    <div class="con">
      <div class="inputLi flex vc hs">
        <div class='lable'>发票类型</div>
        <input class='pic' v-model="info.invoiceType" readonly="readonly" @click="popup = !popup" type="text"
               placeholder="请选择类型"/>
        <img class='back' src="../../assets/img/invoice/back.png" alt="">
      </div>
      <div class="inputLi flex vc hs">
        <div class='lable'>抬头类型</div>
        <van-radio-group class='radio flex vc' v-model="info.type" direction="horizontal" icon-size='16'>
          <van-radio checked-color='#D0AB73' name="1">企业单位</van-radio>
          <van-radio checked-color='#D0AB73' name="2" style='margin-left:20px;'>个人/非企业单位</van-radio>
        </van-radio-group>
      </div>
      <div class="inputLi flex vc hs">
        <div class='lable'>发票抬头</div>
        <input v-model="info.name" type="text" placeholder="企业名称" value=""/>
      </div>
      <div class="inputLi flex vc hs">
        <div class='lable'>税号</div>
        <input v-model="info.taxId" type="text" placeholder="企业税号" value=""/>
      </div>
      <div class="inputLi flex vc hs">
        <div class='lable'>联系方式</div>
        <input v-model="info.contact" type="text" placeholder="请输入联系方式(非必填)" value=""/>
      </div>
      <div class="inputLi flex vc hs">
        <div class='lable'>电子邮箱</div>
        <input v-model="info.email" type="text" placeholder="输入邮箱" value=""/>
      </div>
      <div class="inputLi flex vc hs">
        <div class='lable'>地址</div>
        <input v-model="info.address" type="text" placeholder="填写地址(非必填)" value=""/>
      </div>
      <div class="inputLi flex vc hs">
        <div class='lable'>开户行</div>
        <input v-model="info.bank" type="text" placeholder="填写开户行(非必填)" value=""/>
      </div>
      <div class="inputLi flex vc hs">
        <div class='lable'>账号</div>
        <input v-model="info.account" type="text" placeholder="填写开户行账号(非必填)" value=""/>
      </div>
      <div class="inputLi flex vc hs">
        <div class='lable'>备注</div>
        <input v-model="info.remark" type="text" placeholder="备注(非必填)" value=""/>
      </div>
    </div>
    <div class='line'></div>
    <div class="con">
      <div class="inputLi flex vc hs">
        <div class='lable'>总金额</div>
        <input class='pic' v-model="info.donate" type="text" placeholder="填写开票金额" value=""/>
        <div>元</div>
      </div>
    </div>
    <button class='submit' @click="addInvoice">申请开票</button>
    <van-popup v-model="popup" position="bottom">
      <van-picker show-toolbar :columns="slots" @cancel="popup = !popup" @confirm="onConfirm"/>
    </van-popup>
  </div>
</template>

<script>
import { Popup, Picker, Radio, RadioGroup, Toast } from 'vant'
import { invoiceAdd } from '@/api/invoice'
export default {
  components: {
    [Popup.name]: Popup,
    [Picker.name]: Picker,
    [Radio.name]: Radio,
    [RadioGroup.name]: RadioGroup,
    [Toast.name]: Toast
  },
  data () {
    return {
      info: {
        type: '',
        name: '',
        radio: ''
      },
      popup: false,
      slots: ['普票', '增值税发票']
    }
  },

  created () {
    this.info.donate = this.$route.query.donate
    this.info.donateId = this.$route.query.id
  },

  methods: {
    onConfirm (picker, values) {
      this.info.invoiceType = picker
      this.popup = false
    },
    addInvoice () {
      invoiceAdd(this.info).then(response => {
        Toast({
          message: '添加成功',
          type: 'success',
          duration: 5 * 1000
        })
        this.$router.go(-1)
      })
    }
  }
}
</script>

<style scoped>
  .flex {
    width: auto;
  }

  .box {
    width: 100vw;
    background: #fff;
  }

  .con {
    padding: 0 15px;
  }

  .inputLi {
    padding: 18px 5px;
    border-bottom: 1px solid #EEEEEE;
    font-size: 15px;
    color: #535353;
  }

  .lable {
    width: 90px;
    font-size: 16px;
    color: #000;
  }

  input {
    width: calc(100% - 90px);
    border: 0;
    outline: none;
  }

  .radio {
    font-size: 14px;
  }

  .pic {
    width: calc(100% - 98px);
  }

  .back {
    width: 8px;
    height: 16px;
  }

  .line {
    width: 100%;
    height: 2px;
    background: #E1E0DF;
  }

  .submit {
    display: block;
    width: 328px;
    height: 50px;
    background: #C7AA72;
    color: #fff;
    border-radius: 100px;
    margin: 30px auto;
    text-align: center;
    line-height: 50px;
    font-size: 18px;
    box-shadow: 0px 8px 15px 0px rgba(0, 0, 0, 0.15);
  }
</style>
